@(branch: String,
  repository: gitbucket.core.service.RepositoryService.RepositoryInfo,
  pathList: List[String],
  protectedBranch: Boolean,
  commit: String)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers
@import gitbucket.core.util.FileUtil
@gitbucket.core.html.main(s"Upload Files at ${branch} - ${repository.owner}/${repository.name}", Some(repository)) {
  @gitbucket.core.html.menu("files", repository){
    @if(protectedBranch){
      <div class="alert alert-danger">branch @branch is protected.</div>
    }
    <form method="POST" action="@helpers.url(repository)/upload" id="upload-form" autocomplete="off">
      <div class="head">
        <a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch)">@repository.name</a> /
        @pathList.zipWithIndex.map { case (section, i) =>
          <a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch + "/" + pathList.take(i + 1).mkString("/"))">@section</a> /
        }
        <input type="hidden" name="branch" id="branch" value="@branch"/>
        <input type="hidden" name="path" id="path" value="@pathList.mkString("/")"/>
      </div>
      <table class="table table-bordered">
        <tr>
          <td id="upload-td">
            <div id="upload-area">
              Drag files here to add them to your repository
            </div>
            <ul id="upload-files">
            </ul>
          </td>
        </tr>
      </table>
      <div class="panel panel-default issue-comment-box">
        <div class="panel-body">
          <div>
            <strong>Commit changes</strong>
          </div>
          <div class="form-group">
            <input type="text" name="message" class="form-control"/>
          </div>
          <div class="form-group">
            <div class="col-md-12">
              <label class="radio">
                <input type="radio" id="newBranch" name="newBranch" value="false" checked>
                <i class='octicon octicon-git-commit'></i><span>Commit directly to the <strong style="background-color: lightblue; font-family: Consolas">@branch</strong> branch.</span>
              </label>
              <label class="radio">
                <input type="radio" id="newBranch"  name="newBranch" value="true">
                <i class='octicon octicon-git-pull-request'></i><span>Create a <strong>new branch</strong> for this commit and start a pull request.</span>
              </label>
            </div>
          </div>
          <div style="text-align: right;">
            <a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch + "/" + pathList.mkString("/"))" class="btn btn-default">Cancel</a>
            <input type="submit" id="commit" class="btn btn-success" value="Commit changes" disabled="true"/>
            <input type="hidden" id="upload-files-data" name="uploadFiles" value=""/>
            <input type="hidden" id="commit" name="commit" value="@commit"/>
          </div>
        </div>
      </div>
    </form>
  }
}
<script>
$(function(){
  $('#upload-area').dropzone({
    url: '@context.path/upload/tmp',
    maxFilesize: @{context.settings.upload.maxFileSize / 1024 / 1024},
    timeout: @{context.settings.upload.timeout},
    clickable: true,
    previewTemplate: "<div class=\"dz-preview\">\n  <div class=\"dz-progress\"><span class=\"dz-upload\" data-dz-uploadprogress>Uploading your files...</span></div>\n  <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n</div>",
    success: function(file, id) {
      $(file.previewElement).remove();
      $('#upload-files').append($('<li class="upload-file">')
        .append($('<span>').data('id', id).text(file.name))
        .append($('<a class="delete" href="javascript:void(0);" style="margin-left: 4px;">(delete)</a>')));
      updateCommitButtonStatus();
    }
  });

  $('#upload-form').submit(function(){
    try {
      var data = '';
      $.each($('li.upload-file span'), function(i, e){
        data = data + $(e).data('id') + ':' + $(e).text() + '\n';
      });
      $('#upload-files-data').val(data);
    } catch(e){
      console.log(e);
    }
  });

  $(document).on('click', 'a.delete', function(e){
     $(e.target).parent().remove();
    updateCommitButtonStatus();
  });

  function updateCommitButtonStatus(){
    $('#commit').attr('disabled', $('.upload-file').length == 0);
  }
});
</script>
